package protocol

import "encoding/binary"

const (
	InvliadPacketMainID = uint16(0xFFFF) //0-65535
)

//普通封包
type Packet struct {
	MainId uint16  //主命令ID
	SubId  uint16  //子命令ID
	Data   []byte  //数据
}

func (self *Packet) ToByteArray() []byte {
	buffer := make([]byte, PacketCommandSize)
	binary.LittleEndian.PutUint16(buffer[0:2], self.MainId)
	binary.LittleEndian.PutUint16(buffer[2:4], self.SubId)
	buffer = append(buffer[0:PacketCommandSize], self.Data...)
	return buffer
}


func MakePacket(mainId uint16, subId uint16, data []byte) *Packet {
	return &Packet{
		MainId: mainId,
		SubId:  subId,
		Data:   data,
	}
}
